package com.lucky.service.impl;

import com.lucky.annotation.Cache;
import com.lucky.annotation.CacheEvict;
import com.lucky.pojo.vo.User;
import com.lucky.service.UserService;
import com.lucky.util.UserDBUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Collection;

/**
 * @Description
 * @Author Jalyson
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2019/6/27
 */
@Service("userService")
//@Service("userService11")
public class UserServiceImpl implements UserService {
    /** logger */
    private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class);

    @Override
    public Collection<User> findAll() {
        return UserDBUtil.findAll();
    }

    @Override
    public User save(User obj) {
        return UserDBUtil.save(obj);
    }

    //缓存一个小时
    @Cache(key = "'user_'+#id", ttl = 3600)
    @Override
    public User get(Long id) {
        return UserDBUtil.get(id);
    }

    //删除即清空缓存
    @CacheEvict(key = "'user_'+#id")
    @Override
    public boolean remove(Long id) {
        return UserDBUtil.remove(id);
    }

    @Override
    public User findByUsernameAndPassword(String username, String password) {
        return UserDBUtil.findByUsernameAndPassword(username, password);
    }
}
